package live.cz.dao;

import java.util.LinkedHashMap;
import java.util.Map;

import live.common.PostParam;
import live.common.Verifystring;
import live.cz.entity.Accse;
import live.cz.response.XmlFormart;
import live.response.WebServicePay;

import org.apache.commons.codec.digest.DigestUtils;
import org.dom4j.Document;
import org.dom4j.Element;




public class Accsegment {
	private Accse item =null;
	
	public Accse returnAccsegment(String phonenum){
		Map<String, String> params = new LinkedHashMap<String, String>();
		params.put("agentid", PostParam.AGENTID.toString());
		params.put("source",  PostParam.SOURCE.toString());
		params.put("mobilenum", phonenum);
		String verString = new Verifystring().returnVerifystring(params);
		params.put("verifystring", DigestUtils.md5Hex(verString));
		try {
			String result = new WebServicePay().returnResult(PostParam.ACCSEGMENT.toString(), params);
			if(result.indexOf("<")!=-1){
			Document doc = XmlFormart.xmlToDocument(result);
			Element e = (Element)doc.selectSingleNode("//acc");
			try {
				if(e.asXML().indexOf("<")!=-1){
					item = new Accse();
					item.setProvincename(XmlFormart.returnXmlNodeValue(e, "mobile", "provincename"));
					item.setDetail(XmlFormart.returnXmlNodeValue(e, "mobile", "detail"));
					item.setIsptype(XmlFormart.returnXmlNodeValue(e, "mobile", "isptype"));
					item.setCityCode(XmlFormart.returnXmlNodeValue(e, "mobile", "citycode"));
				}else{
					
				}
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				item = null;
			}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			item = null;
		}finally{
			return item;
		}
	}
}
